package com.example.myeurekaclientconsumer.controller;

import com.example.myeurekaclientconsumer.service.IHelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author Chen Panrui
 * created at 2021/10/29 21:14
 */
@RestController
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private IHelloService helloService;
    private final String applicationName = "eureka-client-service-provider";
    private final String applicationContext = "/demo";

    @RequestMapping(value = "feignRequest")
    public Object feignRequest(){
        String s = helloService.nice();
        System.out.println("s=" + s);
        return s;
    }

    @RequestMapping(value = "commonRequest")
    public Object commonRequest(){
        String url = "http://"+ applicationName + applicationContext +"/hello";
        String s = restTemplate.getForObject(url,String.class);
        System.out.println("url="+url + ",s="+s);
        return s;
    }

}
